package ans.pjz_offer_54;

import ans.base.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * #      剑指 Offer 54
 * 名称   二叉搜索树的第k大节点
 * 链接   https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof
 * 题解   [826](https://leetcode-cn.com/problems/er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/solution)
 * 通过率 74.8%
 * 难道   简单
 */

public class Solution {
    public int kthLargest(TreeNode root, int k) {
        List<Integer> list = new ArrayList<>();
        order(root, list);
        return list.get(list.size() - k);
    }

    public void order(TreeNode root, List<Integer> list) {
        if (root == null) {
            return;
        }
        order(root.left, list);
        list.add(root.val);
        order(root.right, list);
    }
}